package com.iot.tob.platform.controller;


import com.iot.tob.platform.entity.DeviceField;
import com.iot.tob.platform.service.IDeviceFieldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Alex Wu
 * @since 2025-03-24
 */
@RestController
@RequestMapping("/device-field")
public class DeviceFieldController {

    @Autowired
    private IDeviceFieldService deviceFieldService;

    @GetMapping
    public List<DeviceField> getAllDeviceFields() {
        return deviceFieldService.list();
    }

    @GetMapping("/{id}")
    public DeviceField getDeviceFieldById(@PathVariable Long id) {
        return deviceFieldService.getById(id);
    }

    @PostMapping
    public Boolean createDeviceField(@RequestBody DeviceField deviceField) {
        return deviceFieldService.save(deviceField);
    }

    @PutMapping("/{id}")
    public Boolean updateDeviceField(@PathVariable Long id, @RequestBody DeviceField deviceField) {
        return deviceFieldService.updateById(deviceField);
    }

    @DeleteMapping("/{id}")
    public void deleteDeviceField(@PathVariable Long id) {
        deviceFieldService.removeById(id);
    }


}
